package com.jindi.jacococli.biz.business.task;

import com.jindi.jacococli.biz.config.ServiceProjectConfig;
import com.jindi.jacococli.biz.constant.Constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class TaskStartApplicationRunner implements ApplicationRunner, ApplicationContextAware {

    private static final Logger LOGGER = LoggerFactory.getLogger(TaskStartApplicationRunner.class);

    private ApplicationContext applicationContext;

    @Resource
    private ServiceProjectConfig serviceProjectConfig;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        /**
         * 拉取git分析项目列表
         */
        verifyProjectInfo();
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    private void verifyProjectInfo() {
        Environment environment = applicationContext.getEnvironment();
        String property = environment.getProperty(Constant.SERVICE_LIST);
        serviceProjectConfig.updateProjects(property);

    }


}
